this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};this.BX.Landing.Node=this.BX.Landing.Node||{};this.BX.Landing.Node.Text=this.BX.Landing.Node.Text||{};(function(e,t,l){"use strict";var a=function(){function e(t){babelHelpers.classCallCheck(this,e);this.table=t.querySelector(".landing-table");if(!this.table){return}this.node=t;this.tBody=this.node.getElementsByTagName("tbody")[0];this.addTitles(this.node);this.enableEditCells(this.table);this.dragAndDropRows(this);this.dragAndDropCols(this);this.resizeColumn(this);this.buildLines(this);this.addRow(this);this.addCol(this);this.onUnselect(this);this.unselect(this);this.selectAll(this);this.selectRow(this);this.selectCol(this);this.onCopyTable(this);this.onDeleteElementTable(this);this.onShowPopupMenu(this)}babelHelpers.createClass(e,[{key:"addTitles",value:function e(t){if(!t.hasAttribute("title-added")){t.title="";t.querySelector(".landing-table-th-select-all").title=BX.Landing.Utils.escapeText(BX.Landing.Loc.getMessage("LANDING_TABLE_SELECT_TABLE"));t.querySelectorAll(".landing-table-div-col-dnd").forEach((function(e){e.title=BX.Landing.Utils.escapeText(BX.Landing.Loc.getMessage("LANDING_TABLE_DND_COLS"))}));t.querySelectorAll(".landing-table-col-resize").forEach((function(e){e.title=BX.Landing.Utils.escapeText(BX.Landing.Loc.getMessage("LANDING_TABLE_RESIZE_COLS"))}));t.querySelectorAll(".landing-table-col-add").forEach((function(e){e.title=BX.Landing.Utils.escapeText(BX.Landing.Loc.getMessage("LANDING_TABLE_BUTTON_ADD_COL"))}));t.querySelectorAll(".landing-table-row-dnd").forEach((function(e){e.title=BX.Landing.Utils.escapeText(BX.Landing.Loc.getMessage("LANDING_TABLE_DND_ROWS"))}));t.querySelectorAll(".landing-table-row-add").forEach((function(e){e.title=BX.Landing.Utils.escapeText(BX.Landing.Loc.getMessage("LANDING_TABLE_BUTTON_ADD_ROW"))}));t.querySelectorAll(".landing-table-td").forEach((function(e){e.title=BX.Landing.Utils.escapeText(BX.Landing.Loc.getMessage("LANDING_TABLE_BUTTON_CHANGE_TEXT"))}));t.setAttribute("title-added","true")}}},{key:"unselect",value:function e(t){var l=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(t.table){if(!l){t.table.classList.remove("table-selected-all");this.removeClasses(t.table,"landing-table-th-select-all-selected");this.removeClasses(t.table,"landing-table-cell-selected")}this.removeClasses(t.table,"landing-table-row-selected");this.removeClasses(t.table,"landing-table-th-selected");this.removeClasses(t.table,"landing-table-th-selected-cell");this.removeClasses(t.table,"landing-table-th-selected-top");this.removeClasses(t.table,"landing-table-th-selected-x");this.removeClasses(t.table,"landing-table-tr-selected-left");this.removeClasses(t.table,"landing-table-tr-selected-y");this.removeClasses(t.table,"landing-table-col-selected");this.removeClasses(t.table,"landing-table-tr-selected");this.removeClasses(t.table,"table-selected-all-right");this.removeClasses(t.table,"table-selected-all-bottom")}}},{key:"onUnselect",value:function e(t){l.Event.bind(t.table,"click",(function(){var e=["landing-table-th-select-all","landing-table-row-dnd","landing-table-row-add"];var l=babelHelpers.toConsumableArray(event.target.classList).some((function(t){return e.includes(t)}));if(!l){var a=["landing-table-col-dnd"];l=babelHelpers.toConsumableArray(event.target.parentElement.classList).some((function(e){return a.includes(e)}));if(!l){t.unselect(t)}}}))}},{key:"selectAll",value:function e(t){var a=t.table.querySelector(".landing-table-th-select-all");l.Event.bind(a,"click",(function(){var e=false;if(t.table.classList.contains("table-selected-all")){e=true}t.unselect(t,true);var l=t.table.querySelectorAll(".landing-table-tr");var n=0;l.forEach((function(t){var a=t.childNodes;var i=0;var d=0;t.childNodes.forEach((function(e){if(e.nodeType===1){d=i}i++}));if(n>0){var s=a[d];if(e){s.classList.remove("table-selected-all-right")}else{s.classList.add("table-selected-all-right")}}n++;if(n===l.length){a.forEach((function(t){if(t.nodeType===1){if(e){t.classList.remove("table-selected-all-bottom")}else{t.classList.add("table-selected-all-bottom")}}}))}}));a.classList.toggle("landing-table-th-select-all-selected");t.table.classList.toggle("table-selected-all");t.table.querySelectorAll(".landing-table-col-dnd").forEach((function(e){e.classList.toggle("landing-table-cell-selected")}));t.table.querySelectorAll(".landing-table-row-dnd").forEach((function(e){e.classList.toggle("landing-table-cell-selected")}))}))}},{key:"selectRow",value:function e(t){var a=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var n=t.table.querySelectorAll(".landing-table-row-dnd");if(a!==null){var i=[];i[0]=n[a];n=i}n.forEach((function(e){l.Event.bind(e,"click",(function(){if(!event.target.classList.contains("landing-table-row-add")){t.unselect(t);var l=e.parentElement.childNodes;var a=0;l.forEach((function(e){if(e.nodeType===1){if(a===1){e.classList.add("landing-table-tr-selected-left")}if(a>=1){e.classList.add("landing-table-tr-selected-y")}a++}}));e.parentElement.classList.add("landing-table-row-selected");t.tBody.classList.add("landing-table-tr-selected")}}))}))}},{key:"selectCol",value:function e(t){var a=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var n=t.table.querySelectorAll(".landing-table-col-dnd");if(a!==null){var i=[];i[0]=n[a];n=i}n.forEach((function(e){l.Event.bind(e,"click",(function(){if(!event.target.classList.contains("landing-table-col-add")&&!event.target.classList.contains("landing-table-col-resize")){t.unselect(t);var l=e.cellIndex;var a=0;t.tBody.childNodes.forEach((function(e){if(e.nodeType===1){var t=0;var n=0;var i=0;e.childNodes.forEach((function(e){if(e.nodeType===1){if(l===n){i=t}n++}t++}));if(a===0){e.classList.add("landing-table-col-selected");e.childNodes[i].classList.add("landing-table-th-selected-cell")}if(a===1){e.childNodes[i].classList.add("landing-table-th-selected-top")}if(a>=1){e.childNodes[i].classList.add("landing-table-th-selected-x")}a++;e.childNodes[i].classList.add("landing-table-th-selected")}}))}}))}))}},{key:"buildLines",value:function e(t){if(t.node){var l=t.node.querySelector(".landing-table").getBoundingClientRect().width;var a=t.node.querySelector(".landing-table").getBoundingClientRect().height;var n=5;var i=document.querySelectorAll(".landing-table-row-add-line");i.forEach((function(e){e.style.width=l+n+"px"}));var d=document.querySelectorAll(".landing-table-col-add-line");d.forEach((function(e){e.style.height=a+n+"px"}))}}},{key:"getButtonsAddRow",value:function e(t){return t.querySelectorAll(".landing-table-row-add")}},{key:"addRow",value:function e(t){var a=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var n=t.getButtonsAddRow(t.node);if(a!==null){var i=n[a];n=[];n[0]=i}else{n=Array.prototype.slice.call(n,0)}n=Array.prototype.slice.call(n,0);n.forEach((function(e){l.Event.bind(e,"click",(function(){var l=t.table.querySelector(".landing-table-th-selected-cell");var a=0;var n=0;if(l){l.parentNode.childNodes.forEach((function(e){if(a===0&&e===l){a=n}if(e.nodeType===1){n++}}))}var i=document.createElement("th");i.classList.add("landing-table-th","landing-table-row-dnd");if(t.table.classList.contains("table-selected-all")){i.classList.add("landing-table-cell-selected")}var d=e.parentNode.parentNode;var s=babelHelpers.toConsumableArray(d.parentNode.children).indexOf(e.parentNode.parentNode);var o=0;var r=0;t.tBody.childNodes.forEach((function(e){if(e.nodeType===1){r=o}o++}));var c=t.tBody.childNodes[r];var g=document.createElement("td");g.classList.add("landing-table-th","landing-table-td");g.style.width="50px";var u=t.node.querySelector(".landing-table");if(u.hasAttribute("bg-color")){g.style.backgroundColor=u.getAttribute("bg-color")}if(u.hasAttribute("text-color")){g.style.color=u.getAttribute("text-color")}var b=document.createElement("tr");b.classList.add("landing-table-tr");i.title=BX.Landing.Utils.escapeText(BX.Landing.Loc.getMessage("LANDING_TABLE_DND_ROWS"));i.style.width="16px";var h=document.createElement("div");h.classList.add("landing-table-row-add");h.title=BX.Landing.Utils.escapeText(BX.Landing.Loc.getMessage("LANDING_TABLE_BUTTON_ADD_COL"));var f=document.createElement("div");f.classList.add("landing-table-row-add-line");var v=document.createElement("div");v.classList.add("landing-table-div-row-dnd");h.appendChild(f);i.appendChild(h);i.appendChild(v);if(c){var L=c.children.length;var y=[];e.parentNode.parentNode.childNodes.forEach((function(e){if(e.nodeType==1){y.push(e)}}));for(var p=0;p<L;p++){var B=g.cloneNode(true);if(p===a){B.classList.add("landing-table-th-selected","landing-table-th-selected-x")}if(p===0){b.appendChild(i)}else{B.style.width=y[p].style.width;B.style.height=y[p].style.height;b.appendChild(B)}}}e.parentNode.parentNode.parentNode.insertBefore(b,e.parentNode.parentNode.nextSibling);t.buildLines(t);t.enableEditCells(t.node);BX.Landing.Block.Node.Text.currentNode.onChange(true);t.selectRow(t,s);t.addRow(t,s);t.unselect(t);BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}))}))}},{key:"getButtonsAddCol",value:function e(t){return t.querySelectorAll(".landing-table-col-add")}},{key:"addCol",value:function e(t){var a=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var n=t.getButtonsAddCol(t.node);if(a!==null){var i=n[a];n=[];n[0]=i}else{n=Array.prototype.slice.call(n,0)}n.forEach((function(e){l.Event.bind(e,"click",(function(){var l=t.table.querySelector(".landing-table-row-selected");var a=0;var n=0;if(l){l.parentNode.childNodes.forEach((function(e){if(e===l&&a===0){a=n}if(e.nodeType===1){n++}}))}var i;var d;i=document.createElement("th");i.classList.add("landing-table-th","landing-table-col-dnd");i.style.width="50px";if(t.table.classList.contains("table-selected-all")){i.classList.add("landing-table-cell-selected")}var s=e.parentNode.parentNode;var o=babelHelpers.toConsumableArray(s.children).indexOf(e.parentNode);if(t.tBody.childNodes.length>0){var r=0;t.tBody.childNodes.forEach((function(e){if(e.nodeType===1){d=i.cloneNode(true);var l=document.createElement("div");l.classList.add("landing-table-div-col-dnd");l.title=BX.Landing.Utils.escapeText(BX.Landing.Loc.getMessage("LANDING_TABLE_DND_COLS"));var n=document.createElement("div");n.classList.add("landing-table-col-resize");n.title=BX.Landing.Utils.escapeText(BX.Landing.Loc.getMessage("LANDING_TABLE_RESIZE_COLS"));var s=document.createElement("div");s.classList.add("landing-table-col-add");s.title=BX.Landing.Utils.escapeText(BX.Landing.Loc.getMessage("LANDING_TABLE_BUTTON_ADD_COL"));var c=document.createElement("div");c.classList.add("landing-table-col-add-line");s.appendChild(c);d.appendChild(l);d.appendChild(n);d.appendChild(s);var g=document.createElement("td");g.classList.add("landing-table-th","landing-table-td");g.style.width="50px";var u=t.node.querySelector(".landing-table");if(u.hasAttribute("bg-color")){g.style.backgroundColor=u.getAttribute("bg-color")}if(u.hasAttribute("text-color")){g.style.color=u.getAttribute("text-color")}if(a>0&&a===r){g.classList.add("landing-table-tr-selected-y")}var b=0;var h=0;var f=0;e.childNodes.forEach((function(e){if(e.nodeType===1){if(h===o){f=b}h++}b++}));if(r===0){e.childNodes[f].parentNode.insertBefore(d,e.childNodes[f].nextSibling)}else{e.childNodes[f].parentNode.insertBefore(g,e.childNodes[f].nextSibling)}r++}}))}t.buildLines(t);t.enableEditCells(t.node);BX.Landing.Block.Node.Text.currentNode.onChange(true);t.selectCol(t,o);t.addCol(t,o);t.unselect(t);BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}))}))}},{key:"dragAndDropRows",value:function e(l){var a=this;this.draggableRows=new t.Draggable({container:l.tBody,draggable:".landing-table-tr",dragElement:".landing-table-row-dnd",type:t.Draggable.HEADLESS});var n=[];var i;var d;var s;var o=0;var r;var c;var g;var u;var b;var h;var f;this.draggableRows.subscribe("start",(function(e){f=a.draggableRows.dragStartEvent.data.originalSource;c=l.tBody.getBoundingClientRect().left;g=l.tBody.getBoundingClientRect().top;i=[];d=[];r=0;s=e.getData().sourceIndex;n=l.tBody.querySelectorAll(".landing-table-tr");n.forEach((function(e){i.push(e.getBoundingClientRect().y);d.push(e.getBoundingClientRect().height)}));u=n[s].getBoundingClientRect().x;b=n[s].getBoundingClientRect().y;h=document.createElement("tr");h.classList.add("landing-table-tr-draggable");n[s].childNodes.forEach((function(e){h.append(e.cloneNode(true))}));if(n[s].classList.contains("landing-table-row-selected")){h.classList.add("landing-table-row-selected")}var t;var o=0;while(!t){if(n[s].childNodes[o].nodeType===1){t=o}o++}h.childNodes[t].style.borderRadius=getComputedStyle(n[s].childNodes[t]).borderRadius})).subscribe("move",(function(e){if(!f.classList.contains("landing-table-row-add")){l.tBody.classList.add("landing-table-draggable");n[s].classList.add("landing-table-tr-taken");r=e.getData().offsetY;l.tBody.append(h);h.style.position="absolute";h.style.top=b-g+r-.5+"px";h.style.left=u-c-.5+"px";if(r>0){h.style.transform="rotate(-1deg)"}else{h.style.transform="rotate(1deg)"}}})).subscribe("end",(function(){h.remove();n[s].classList.remove("landing-table-tr-taken");n[s].style="";var e=b+r;var t=e+n[s].getBoundingClientRect().height;if(r<0){for(var a=0;a<i.length;a++){var c=i[a];if(a===s){c=i[a]-d[a-1]/2}if(e>=c){o=a}}}if(r===0){o=s}if(r>0){for(var g=0;g<i.length;g++){var u=i[g]+d[g]/2;if(g===s){u=i[g]}if(t>=u){o=g}}}if(o===0){o++}if(s!==o){var f=null;var v=null;if(n[o]){f=n[o];v=f.nextSibling;while(v&&v.nodeType!==1){v=v.nextSibling}}if(s>o){l.tBody.insertBefore(n[s],f)}if(s<o){l.tBody.insertBefore(n[s],v)}}l.tBody.classList.remove("landing-table-draggable");BX.Landing.Block.Node.Text.currentNode.onChange(true)}))}},{key:"dragAndDropCols",value:function e(l){this.draggableCols=new t.Draggable({container:l.tBody,draggable:".landing-table-div-col-dnd",type:t.Draggable.HEADLESS});var a;var n=0;var i;var d;var s=[];var o;var r;var c;var g;var u;var b;var h;this.draggableCols.subscribe("start",(function(e){g=l.tBody.getBoundingClientRect().left;o=[];r=[];b=[];i=0;d=0;a=e.getData().originalSource.parentNode.cellIndex;if(a){s=babelHelpers.toConsumableArray(l.tBody.querySelectorAll(".landing-table-tr")).map((function(e){return e.children[a]}));c=l.tBody.querySelectorAll(".landing-table-tr");c[0].childNodes.forEach((function(e){if(e.nodeType===1){o.push(e.getBoundingClientRect().x);r.push(e.getBoundingClientRect().width)}}))}u=s[0].getBoundingClientRect().x;h=document.createElement("div");s.forEach((function(e){b.push(e.getAttribute("style"));h.append(e.cloneNode(true));h.lastChild.style.borderRadius=getComputedStyle(e).borderRadius;h.lastChild.style.height=e.getBoundingClientRect().height+"px";h.lastChild.style.width=e.getBoundingClientRect().width+"px"}));h.hidden=true;h.classList.add("landing-table-col-draggable");l.tBody.append(h)})).subscribe("move",(function(e){l.tBody.classList.add("landing-table-draggable");s.forEach((function(e){e.classList.add("landing-table-col-taken")}));i=e.getData().offsetX;d=e.getData().offsetY;h.hidden=false;h.style.position="absolute";h.style.left=u-g+i+"px";h.style.top=0+"px";if(i<0){h.style.transform="rotate(-1deg)"}if(i>0){h.style.transform="rotate(1deg)"}})).subscribe("end",(function(){h.remove();s.forEach((function(e){e.hidden=false}));if(a){var e=o[a]+i;var t=o[a]+i+s[0].getBoundingClientRect().width;var d=0;s.forEach((function(e){e.style=b[d];e.classList.remove("landing-table-col-taken");d++}));if(i<0){for(var g=0;g<o.length;g++){var u=o[g];if(g>0){u=o[g]-r[g-1]/2}if(e>u){n=g}}}if(i===0){n=a}if(i>0){for(var f=0;f<o.length;f++){var v=o[f]+r[f]/2;if(f===a){v=o[f]}if(t>v){n=f}}}if(n===0){n++}if(a!==n){c.forEach((function(e){var t=[];e.childNodes.forEach((function(e){if(e.nodeType===1){t.push(e)}}));var l=null;var i=null;if(t[n]){l=t[n];i=l.nextSibling;while(i&&i.nodeType!==1){i=i.nextSibling}}if(a>n){e.insertBefore(t[a],l)}if(a<n){e.insertBefore(t[a],i)}}))}l.tBody.classList.remove("landing-table-draggable");BX.Landing.Block.Node.Text.currentNode.onChange(true)}}))}},{key:"resizeColumn",value:function e(l){var a=this.tBody;this.resizeElement=new t.Draggable({container:a,draggable:".landing-table-col-resize",type:t.Draggable.HEADLESS});var n;var i;this.resizeElement.subscribe("start",(function(e){i=[];var t=e.getData().draggable.parentNode;n=t.getBoundingClientRect().width;var l=t.cellIndex;var d=a.querySelectorAll(".landing-table-tr");d.forEach((function(e){i.push(e.children[l])}))})).subscribe("move",(function(e){var t=e.getData().offsetX;var l=n+t;i.forEach((function(e){BX.Dom.style(e,"width","".concat(l,"px"))}))})).subscribe("end",(function(){var e=a.getBoundingClientRect().width;var t=a.parentElement.parentElement.getBoundingClientRect().width;if(t>e){a.parentElement.parentElement.classList.add("landing-table-scroll-hidden")}else{a.parentElement.parentElement.classList.remove("landing-table-scroll-hidden")}l.buildLines(l);BX.Landing.Block.Node.Text.currentNode.onChange(true)}))}},{key:"enableEditCells",value:function e(t){var l=t.querySelectorAll(".landing-table-td");l.forEach((function(e){e.setAttribute("contenteditable","true")}))}},{key:"removeClasses",value:function e(t,l){var a=t.querySelectorAll("."+l);a.forEach((function(e){e.classList.remove(l)}))}},{key:"onCopyTable",value:function e(t){BX.Event.EventEmitter.subscribe("BX.Landing.TableEditor:onCopyTable",(function(){t.unselect(t);BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}))}},{key:"onShowPopupMenu",value:function e(t){BX.Event.EventEmitter.subscribe("BX.Landing.PopupMenuWindow:onShow",(function(){t.unselect(t);BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}))}},{key:"onDeleteElementTable",value:function e(t){BX.Event.EventEmitter.subscribe("BX.Landing.TableEditor:onDeleteElementTable",(function(){t.buildLines(t)}))}}]);return e}();e.default=a})(this.BX.Landing.Node.Text.TableEditor=this.BX.Landing.Node.Text.TableEditor||{},BX.UI.DragAndDrop,BX);
//# sourceMappingURL=tableeditor.bundle.map.js